package com.xyx.ssm.action;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.xyx.ssm.po.Syuser;
import com.xyx.ssm.po.Syuserrole;
import com.xyx.ssm.service.SyuserService;

@Controller
@RequestMapping(value = "/login")
public class LoginAction {
	@Resource
	private SyuserService syuserservice;
	
	/**
	 * 登陆
	 * @return
	 */
	@RequestMapping("/login")
	public String  login(HttpSession session,Syuser syuser){
		
		List<Syuserrole> userrole=syuserservice.login1(syuser);
		session.setAttribute("syuser", syuser);
		if(userrole.size()!=0){
			
			return "index";
		}
		else {
			return "../../login/login";
		}
	}
	@RequestMapping("/login11")
	@ResponseBody
	public List<Map<String, Object>> login11(HttpSession session){
		Syuser user=(Syuser) session.getAttribute("syuser");
		List<Syuserrole> userrole=syuserservice.login1(user);
		System.out.println();
		List<Integer> list=new ArrayList<Integer>();
		for(Syuserrole syuserrole:userrole){
			list.addAll(syuserservice.login3(syuserrole.getRoleid()));
		}
		for ( int i = 0 ; i < list.size() - 1 ; i ++ ) {  
		     for ( int j = list.size() - 1 ; j > i; j -- ) {  
		       if (list.get(j).equals(list.get(i))) {  
		         list.remove(j);  
		       }   
		      }   
		    }
		
		List<Map<String,Object>> list1=new ArrayList<Map<String,Object>>();
		for(Integer a:list){			
			Map<String,Object> map= syuserservice.login4(a);
			
			list1.add(map);
		}
		System.out.println(list1+"????????????????????????????????");
		
		return list1;
		
		
	}
}
